package com.example.clxy.controller;

import com.example.clxy.entity.Announcement;
import com.example.clxy.interceptor.AppToken;
import com.example.clxy.result.PageResult;
import com.example.clxy.result.WebRestResult;
import com.example.clxy.result.business.AnnouncementResult;
import com.example.clxy.result.business.PageResult.AnnouncementPageResult;
import com.example.clxy.service.AnnouncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author Hsieh
 * @title: AnnouncementController
 * @projectName clxy
 * @description: 公告/通知控制器
 * @date 2020/8/4 12:59
 */
@AppToken
@RestController
@RequestMapping("AnnouncementController")
public class AnnouncementController {
    @Autowired
    AnnouncementService announcementService;

    /**
    * @Author:hsieh
    * @Date: 2020/8/4 15:48
      * @param
     * @Description:获取所有通知
     *
     */
    @CrossOrigin
    @RequestMapping("getAnnouncementList")
    public PageResult<AnnouncementPageResult> getAnnouncementList(String title,int page,int pagesize){
        PageResult<AnnouncementPageResult> result=announcementService.getAnnouncementList(title,page,pagesize);
        return  result;
    }
    /**
    * @Author:hsieh
    * @Date: 2020/8/7 11:14
      * @param
     * @Description:获取单个通知byId
     *
     */
    @CrossOrigin
    @RequestMapping("getAnnouncementbyid")
    public AnnouncementResult getAnnouncementbyid(String announcementid){
        AnnouncementResult announcementResult=announcementService.getAnnouncementbyid(announcementid);
        return announcementResult;
    }



    /**
    * @Author:hsieh
    * @Date: 2020/8/5 15:43
      * @param
     * @Description:获取所有动态
     *
     */
    @CrossOrigin
    @RequestMapping("getNewsList")
    public PageResult<AnnouncementPageResult> getNewsList(String title,int page,int pagesize){
        PageResult<AnnouncementPageResult> result=announcementService.getNewsList(title,page,pagesize);
        return  result;
    }


    /**
    * @Author:hsieh
    * @Date: 2020/8/4 17:56
      * @param
     * @Description:新增通知
     *
     */
    @CrossOrigin
    @PostMapping("addAnnouncement")
    public WebRestResult addAnnouncement(@RequestBody Announcement announcement){
        WebRestResult result = announcementService.addAnnouncement(announcement);
        return result;
    }
    /**
    * @Author:hsieh
    * @Date: 2020/8/4 16:05
      * @param
     * @Description:修改通知
     *
     */
    @CrossOrigin
    @PostMapping("updateAnnouncement")
    public WebRestResult updateAnnouncement(@RequestBody Announcement announcement){
        WebRestResult result=announcementService.updateAnnouncement(announcement);
        return result;
    }
    /**
    * @Author:hsieh
    * @Date: 2020/8/4 16:08
      * @param
     * @Description:删除通知
     *
     */
    @CrossOrigin
    @PostMapping("deleteAnnouncement")
    public WebRestResult deleteAnnouncement(String announcementid){
        WebRestResult result = announcementService.deleteAnnouncement(announcementid);
        return result;
    }
    @CrossOrigin
    @PostMapping("uploadPhoto")
    public WebRestResult uploadPhoto(MultipartFile photo,String announcementid){
        WebRestResult result= announcementService.uploadPhoto(photo,announcementid);
        return result;
    }
}
